﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Util.Media;
using System.IO;
using Util.Media.Flash;
using System.Drawing.Drawing2D;

namespace Test
{
    public partial class SwfImageForm : Form
    {
        public SwfImageForm()
        {
            InitializeComponent();
        }

        private void LoadFile(string filename, bool displayImage)
        {
            if (!displayImage)
            {
                using (Stream stream = File.OpenRead(filename))
                {
                    var swf = new Util.Media.Flash.FlashFile(stream);
                    propertyGrid1.SelectedObject = swf;
                    //propertyGrid1.ExpandAllGridItems();
                }
            }
            else
            {
                using (Stream stream = File.OpenRead(filename))
                {
                    SwfImage swf = new SwfImage(stream);
                    propertyGrid1.SelectedObject = swf;
                }
            }
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            // Load a collection of images.
            string path = "../../data/swf/";

            GdiImageSequence gis = new GdiImageSequence();
            int delay = 500; // milliseconds
            int width = 1024; // desired image size
            int height = 768;
            for (int i = 0; i < 5; i++)
            {
                using (Bitmap bmp = new Bitmap(path + (i + 1) + ".png"))
                {
                    gis.AddFrame(new Bitmap(bmp, width, height), delay, true);
                }
            }

            // Write SWF file.
            string filename = "../../data/swf/mine.swf";
            SwfImageEncoder.Encode(gis, filename);

            // Take a look at the file we saved.
            LoadFile(filename, false);
        }

        private void SwfImageForm_Load(object sender, EventArgs e)
        {
            //LoadFile("../../data/swf/mine.swf");
            //LoadFile("../../data/swf/output.swf", false);
            LoadFile("../../data/swf/default_loader.swf", false);
        }
    }


}
